<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //接口地址:http://localhost:64352/goods/GetGoodsList?token=000

        const p = new Promise(function (resolve, reject) {
            //1.创建对象
            const xhr = new XMLHttpRequest;

            //2.初始化
            xhr.open('GET', 'http://localhost:64352/goods/GetGoodsList?token=000');

            //3.发送
            xhr.send();

            //4.绑定事件，处理相应结果
            xhr.onreadystatechange = function () {
                //判断 等于4代表进入了最后的阶段，响应体全部回来了
                if (xhr.readyState == 4) {
                    //成功响应码200-300
                    if (xhr.status >= 200 && xhr.status <= 300) {
                        //表示成功
                        resolve(xhr.response);
                    } else {
                        reject(xhr.status);
                    }
                }
            }
        })
         

        //调用then方法
        p.then(function(value){
            console.log(value);
        },function(reason){
          console.error(reason);
        })
    </script>
</body>

</html>